package org.example.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Lenovo
 * @version 1.0
 * @description TODO
 * @date 30/7/2023 上午10:42
 */
@SpringBootConfiguration // 声明当前类是一个配置类
public class RabbitMQConfig {
    public static final String EXCHANGE_NAME = "springboot_exchange";
    public static final String QUEUE_NAME = "springboot_queue";

    // 创建交换机
    @Bean
    public  Exchange getExchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    // 创建队列
    @Bean
    public Queue getqueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    // 将队列绑定到交换机
    @Bean
    public Binding binding(Exchange exchange, Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("springboot.#").noargs();
    }
}
